<?php

namespace App\Utils;

use App\Imports\GeneralImport;
use Maatwebsite\Excel\Facades\Excel;

class UploadHelper
{
    public static function readExcel($file)
    {
        if ($file->isValid()) {
            $vailExtension = ['xlsx', 'xls'];
            if (!in_array($file->getClientOriginalExtension(), $vailExtension)) {
                throw new \Exception('文件格式错误');
            }

            return Excel::toArray(new GeneralImport(), $file)[0];
        }

        throw new \Exception('文件无效');
    }
}
